<script setup>
import { ref, onMounted, getCurrentInstance } from 'vue'
import * as echarts from 'echarts'
import { radarData } from '@/socket'

const props = defineProps({
  radius: {
    type: [String, Array],
    default: '50%'
  }
})
const main = ref(null)
const { proxy } = getCurrentInstance()
const initChart = (myChart) => {
  // 绘制图表
  myChart.setOption({
    radar: {
      indicator: [
        { name: 'Sales', max: 50000 },
        { name: 'Administration', max: 50000 },
        { name: 'Information Technology', max: 50000 },
        { name: 'Customer Support', max: 50000 },
        { name: 'Development', max: 50000 },
        { name: 'Marketing', max: 50000 }
      ],
      axisName: {
        color: 'skyblue'
      }
    },
    series: [
      {
        name: 'Budget vs spending',
        type: 'radar',
        data: [
          {
            value: radarData,
            name: 'Allocated Budget'
          }
        ]
      }
    ]
  })
}
onMounted(() => {
  // 基于准备好的dom，初始化echarts实例
  const myChart = echarts.init(proxy.$refs.main)
  setInterval(() => initChart(myChart), 1000)
})
</script>

<template>
  <div id="main" ref="main"></div>
</template>

<style lang="scss" scoped>
#main {
  width: 100%;
  height: 100%;
}
</style>
